<template>
  <el-dialog
  :title="dialogTitle"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
    <el-form
    :model="auditForm"
    ref="auditForm"
    :rules="rules"
    label-width="100px">
      <el-form-item label="商户编号:" prop="merchantsNo">
        <el-input v-model="auditForm.merchantsNo" placeholder="请输入商户编号" @change="formChange"></el-input>
      </el-form-item>
      <el-form-item label="备注:">
        <el-input type="textarea" rows="2" v-model="auditForm.remark" placeholder="请输入备注" @change="formChange"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  name: 'MerchantsAudit',
  props: {
    title: {
      type: String,
      default: ()=> '提示'
    },
    visible: {
      type: Boolean,
      default: ()=>  false
    },
    form: {
      type: Object,
      default: ()=> {}
    }
  },
  data() {
    return {
      auditForm: {
        merchantsNo: this.$common.generateRandomNumberString(8),
        remark: ''
      },
      rules: {
        merchantsNo: [{ required: true, message: '请输入商户编号', trigger: 'blur, change' }]
      }
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible
      }
    },

    dialogTitle: {
      get() {
        return this.title
      }
    }
  },
  methods: {
    // 表单值发生变化
    formChange() {
      this.$emit('update:form', this.auditForm)
    },

    // 关闭
    handleClose() {
      this.$refs.auditForm.resetFields()
      this.$emit('update:form', null)
      this.$emit('update:visible', false)
    },

    // 确定
    handleConfirm() {
      this.$refs.auditForm.validate((valid)=> {
        if(!valid) return
        this.$emit('confirm')
      })
    }
  }
}
</script>
<style lang="scss" scoped>

</style>